﻿

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>部位管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">部位名称</label>
            <div class="layui-input-block">
              <input type="text" name="bwname" id="bwname" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">部位简称</label>
            <div class="layui-input-block">
              <input type="text" name="bwothername" id="bwothername" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
        
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>
      
      <div class="layui-card-body">
          <div style="padding-bottom: 10px;">
              <button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>
              <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
          </div>

          <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
          <div id="laypage"></div>
          <script type="text/html" id="test-table-operate-td">
              <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
              <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
          </script>

          <script type="text/html" id="imgTpl">
              <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
          </script>
      </div>
    </div>
  </div>
  <script src="../../../layuiadmin/layui/layui.js"></script>  
  <script>
      //列表查询方法
          layui.config({
              base: '../../../layuiadmin/' //静态资源所在路径
          }).extend({
              index: 'lib/index' //主入口模块
          }).use(['index', 'useradmin', 'table', 'laypage'], function () {
              var $ = layui.$
                  , form = layui.form
                  , table = layui.table
                  , laypage = layui.laypage;
              table.render({
                  elem: '#LAY-user-manage'
                  , id: 'testReload'//容器的ID
                  , url: 'ashx/list.ashx?type=getlist'
                  , toolbar: '#test-table-radio-toolbarDemo'
                  , method: 'POST'
                  , page: true
                  , limits: [10, 20, 30]
                  , limit: 10
                  , cols: [[
                      { type: 'checkbox' }
                      , { field: 'id', width: 60, title: 'id', align: 'center' }
                      , { field: 'bwname', width: 150, title: '部位名称', align: 'center' }
                      , { field: 'bwothername', width: 150, title: '部位简称', align: 'center' }
                      , { field: 'bwremark', width: 150, title: '部位描述', align: 'center' }
                      , { field: 'publicerrand', width: 100, title: '公差', align: 'center' }
                      , { field: 'maxvalue', width: 100, title: '最大修改值', align: 'center' }
                      , { field: 'minvalue', width: 100, title: '最小修改值', align: 'center' }
                      , { field: 'xh', width: 80, title: '排序', align: 'center', sort: true}
                      , { field: 'createtime', width: 180, title: '创建时间', align: 'center', sort: true }
                      , { field: 'modifytime', width: 180, title: '修改时间', align: 'center', sort: true }
                      , { width: 178, align: 'center', fixed: 'right', toolbar: '#test-table-operate-td' }

                  ]]
                  , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据.
                      return {
                          "code": res.code, //解析接口状态
                          "msg": res.msg, //解析提示文本
                          "count": res.count, //解析数据长度
                          "data": res.data //解析数据列表
                      };
                  }
                  , where: {
                      bwname: $('#bwname').val(),
                      bwothername: $('#bwothername').val()
                  }
                 
              });
              //监听工具条
              table.on('tool(LAY-user-manage)', function (obj) {
                  var data = obj.data;
                  if (obj.event === 'detail') {
                      layer.msg('ID：' + data.id + ' 的查看操作');
                  } else if (obj.event === 'del') {
                      layer.confirm('真的删除行么', function (index) {
                          $.ajax({
                              url: 'ashx/list.ashx?type=delete&getids=' + data.id,
                              type: "post",
                              contentType: "application/json",
                              dataType: "json",
                              data: {},
                              success: function (res) {
                                  var index = parent.layer.getFrameIndex(window.name);
                                  if (res.flag == "True") {
                                      layer.msg(res.remsg, {
                                          time: 2000,
                                          end: function () {
                                              //执行重载
                                              table.reload('testReload', {
                                                  where: {
                                                      bwname: $('#bwname').val(),
                                                      bwothername: $('#bwothername').val()
                                                  }, page: {
                                                      curr: 1 //重新从第 1 页开始
                                                  }
                                              });
                                          }
                                      })
                                  }
                                  else {
                                      layer.alert(res.remsg);
                                  }
                              }
                          });
                      });
                  } else if (obj.event === 'edit') {
                      layer.open({
                          type: 2
                          , title: '修改'
                          , content: 'edit.html?editid=' + data.id
                          , maxmin: true
                          , area: [($(window).width() * 0.5) + 'px', ($(window).height() * 0.7) + 'px']
                          ,end: function () {
                              //执行重载
                              table.reload('testReload', {
                                  where: {
                                      bwname: $('#bwname').val(),
                                      bwothername: $('#bwothername').val()
                                  }, page: {
                                      curr: 1 //重新从第 1 页开始
                                  }
                              });
                          }
                      });
                      //layer.alert('编辑行：<br>' + JSON.stringify(data))
                  }
              });
              //监听搜索
              form.on('submit(LAY-user-front-search)', function (data) {
                  var field = data.field;
                  //执行重载
                  table.reload('testReload', {
                      where: {
                          bwname: field.bwname, 
                          bwothername: field.bwothername 
                      }, page: {
                          curr: 1 //重新从第 1 页开始
                      }
                  });
              });
              function getRowFexId(value) {
                  var checkStatus = table.checkStatus('LAY-user-manage')
                      , data = checkStatus.data, arr = new Array();;
                  for (var i = 0; i < data.length; i++) {
                      arr.push(data[i][value]);
                  }
                  return arr.join(",");
              }
              //监听排序
              table.on('sort(LAY-user-manage)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                  table.reload('testReload', {//刷新列表
                      initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。 layui 2.1.1 新增参数
                      , where: { //请求参数
                          field: obj.field //排序字段
                          , order: obj.type //排序方式
                          , bwname: $('#bwname').val()
                          , bwothername: $('#bwothername').val()
                      }
                  });
              });
              //事件
              var active = {
                  batchdel: function () {
                      var checkStatus = table.checkStatus('LAY-user-manage')
                          , checkData = checkStatus.data; //得到选中的数据
                      if (checkData.length === 0) {
                          return layer.msg('请选择数据');
                      }
                      var getid = getRowFexId("id");
                      layer.confirm('确定删除吗？', function (index) {
                          //执行 Ajax 后重载
                          $.ajax({
                              url: 'ashx/list.ashx?type=delete&getids=' + getid,
                              type: "post",
                              contentType: "application/json",
                              dataType: "json",
                              data: {},
                              success: function (res) {
                                  var index = parent.layer.getFrameIndex(window.name);
                                  if (res.flag == "True") {
                                      layer.msg(res.remsg, {
                                          time: 2000,
                                          end: function () {
                                              //执行重载
                                              table.reload('testReload', {
                                                  where: {
                                                      bwname: $('#bwname').val(),
                                                      bwothername: $('#bwothername').val()
                                                  }, page: {
                                                      curr: 1 //重新从第 1 页开始
                                                  }
                                              });
                                          }
                                      })
                                  }
                                  else {
                                      layer.alert(res.remsg);
                                  }
                              }
                          });
                      });
                  }
                  , add: function () {
                      layer.open({
                          type: 2
                          , title: '添加类型'
                          , content: 'add.html'
                          , maxmin: true
                          , area: [($(window).width() * 0.5) + 'px', ($(window).height() * 0.5) + 'px']
                          ,end: function () {
                              //执行重载
                              table.reload('testReload', {
                                  where: {
                                      bwname: $('#bwname').val(),
                                      bwothername: $('#bwothername').val()
                                  }, page: {
                                      curr: 1 //重新从第 1 页开始
                                  }
                              });
                          }

                      });
                  }
              };
              $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
                  var type = $(this).data('type');
                  active[type] ? active[type].call(this) : '';
              });
          });

  </script>
</body>
</html>
